package com.sojson.project.verifycode.task;

import java.io.File;

import org.springframework.context.annotation.Conditional;
import org.springframework.stereotype.Component;

import com.sojson.config.condition.TaskCondition;
import com.sojson.project.verifycode.service.VerifyCodeService;
import com.sojson.task.TaskInterface;
import com.sojson.util.file.FileUtil;

import lombok.extern.slf4j.Slf4j;

/**
 * 自定义验证码定时任务
 * 
 * @author liu
 * @date 2021-04-28
 */
@Slf4j
@Component
/** 是否注入这个Bean */
@Conditional(TaskCondition.class)
public class CustomVerifyCodeTask implements TaskInterface {

    /**
     * 清空本地验证码文件
     */
    public void clearVerifyCodeImgThisLocal() {
        File file = new File(FileUtil.THIS_LOCALITY_DIRECTORY_BUCKET_NAME_BASE + VerifyCodeService.VERIFY_IMG);
        if (!file.exists()) {
            return;
        }

        File[] listFiles = file.listFiles();
        for (File f : listFiles) {
            f.delete();
        }
        log.info("---------------当天0 点 清除本地验证码文件----------------");
    }

}